// $.get("header_menu.html",function(data){ $("#header").html(data); });
$.get("footer.html",function(data){ $("#footer").html(data); });

function pic_replace(dom1, dom2) {
    var file = document.getElementById(dom1).files;
    var reader = new FileReader();
    reader.readAsDataURL(file[0]);
    reader.onload = function (e) {
        var Img = '<img class="img_sty" src="' + this.result + '"/>';
        $('.' + dom2).html(Img)
    }
}

$(document).ready(function() {
    // $("#store").addClass("active");
    // $("#store2").addClass("active");

    $("#submit").click(function () {
        var textOnoff = true;

        //判断必填信息
        if ($('#store_name').val() == '' && textOnoff == true) {
            textOnoff = false;
            layer.msg('请填写店面名称');

        } else if ($('#time').val() == '' && textOnoff == true) {
            textOnoff = false;
            layer.msg('请填写营业时间');

        } else if ($('#store_phone').val() == '' && textOnoff == true) {
            textOnoff = false;
            layer.msg('请填写店面电话');

        } else if ($('#store_address').val() == '' && textOnoff == true) {
            layer.msg('请填写店面地址');
            textOnoff = false;
        } else if ($('#store_summary').val() == '' && textOnoff == true) {
            layer.msg('请填写店面简介');
            textOnoff = false;
        }else if ($('.pic2').text() == '+' && textOnoff == true) {
            layer.msg('请添加店面图片');
            textOnoff = false;
        }

        if (textOnoff) {
            var formData = new FormData(document.getElementById('store_banner'));
            formData.append('storeName', $('input[name=storeName]').val());
            formData.append('businessHour', $('input[name=businessHour]').val());
            formData.append('storePhone', $('input[name=storePhone]').val());
            formData.append('storeAddress', $('input[name=storeAddress]').val());
            formData.append('storeContent', $('#store_summary').val());
            $.ajax({
                type: 'POST',
                url: 'http://114.116.72.220:9999/AddStore/',
                async: true,
                data: formData,
                processData: false,
                contentType: false,
                success: data => {
                    if (data == 'success') {
                        layer.msg('新建店面信息成功！', {time: 500}, function () {
                            location.reload();
                        });

                    } else {
                        layer.msg('新建失败！')
                    }
                }
            });
        }

    });

});
